<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-item label="成果ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['cxjCxjId']" placeholder="请输入成果ID"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrXm']" placeholder="请输入姓名"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="序号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrXh']" placeholder="请输入序号"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrXb']" placeholder="请输入性别"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="出生地" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrCsd']" placeholder="请输入出生地"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="民族" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrMz']" placeholder="请输入民族"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="出生日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择出生日期" v-decorator="['wcrCsrq']" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="党派" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrDp']" placeholder="请输入党派"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="国家" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrGj']" placeholder="请输入国家"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrSfzh']" placeholder="请输入身份证号"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="行政职务" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrXzzw']" placeholder="请输入行政职务"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="是否归国人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-switch v-decorator="['wcrSfgg']"  ></j-switch>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="归国时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择归国时间" v-decorator="['wcrGgsj']" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="工作单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrGzdw']" placeholder="请输入工作单位"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="办公电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrBgdh']" placeholder="请输入办公电话"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="通讯地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrTxdz']" placeholder="请输入通讯地址"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="邮编" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrYb']" placeholder="请输入邮编"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="家庭住址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrJtzz']" placeholder="请输入家庭住址"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="住址电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrZzdh']" placeholder="请输入住址电话"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrYx']" placeholder="请输入邮箱"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="手机" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrSj']" placeholder="请输入手机"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="毕业学校" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrByxx']" placeholder="请输入毕业学校"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="文化程度" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrWhcd']" placeholder="请输入文化程度"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="最高学位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrZgxw']" placeholder="请输入最高学位"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="职称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrZc']" placeholder="请输入职称"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="专业" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrZy']" placeholder="请输入专业"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="毕业时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择毕业时间" v-decorator="['wcrBysj']" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="曾获奖励及荣誉" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrChjj']" placeholder="请输入曾获奖励及荣誉"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="参加本成果起始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择参加本成果起始时间" v-decorator="['wcrXmqssj']" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="参加本成果截止时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择参加本成果截止时间" v-decorator="['wcrXmjzsj']" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="贡献百分比" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['wcrBfb']" placeholder="请输入贡献百分比" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="贡献" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrGx']" placeholder="请输入贡献"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="声明" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrSm']" placeholder="请输入声明"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="旁证材料附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrPath']" placeholder="请输入旁证材料附件"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="签字附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrqzPath']" placeholder="请输入签字附件"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="荣誉称号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wcrRych']" placeholder="请输入荣誉称号"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="是否有效" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-switch v-decorator="['isValid']"  ></j-switch>
            </a-form-item>
          </a-col>
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CxjSbWcrForm',
    components: {
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/cxj/cxjSbWcr/add",
          edit: "/cxj/cxjSbWcr/edit",
          queryById: "/cxj/cxjSbWcr/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'cxjCxjId','wcrXm','wcrXh','wcrXb','wcrCsd','wcrMz','wcrCsrq','wcrDp','wcrGj','wcrSfzh','wcrXzzw','wcrSfgg','wcrGgsj','wcrGzdw','wcrBgdh','wcrTxdz','wcrYb','wcrJtzz','wcrZzdh','wcrYx','wcrSj','wcrByxx','wcrWhcd','wcrZgxw','wcrZc','wcrZy','wcrBysj','wcrChjj','wcrXmqssj','wcrXmjzsj','wcrBfb','wcrGx','wcrSm','wcrPath','wcrqzPath','wcrRych','isValid'))
        })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'cxjCxjId','wcrXm','wcrXh','wcrXb','wcrCsd','wcrMz','wcrCsrq','wcrDp','wcrGj','wcrSfzh','wcrXzzw','wcrSfgg','wcrGgsj','wcrGzdw','wcrBgdh','wcrTxdz','wcrYb','wcrJtzz','wcrZzdh','wcrYx','wcrSj','wcrByxx','wcrWhcd','wcrZgxw','wcrZc','wcrZy','wcrBysj','wcrChjj','wcrXmqssj','wcrXmjzsj','wcrBfb','wcrGx','wcrSm','wcrPath','wcrqzPath','wcrRych','isValid'))
      },
    }
  }
</script>